home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / lib / posix / closedir.c < prev    next >
C/C++ Source or Header  |  1990-07-19  |  760b  |  33 lines

  1. /* closedir -- close a directory stream        Author: D.A. Gwyn */
  2.  
  3. /*    last edit:    11-Nov-1988    D A Gwyn    */
  4.  
  5. #include <stddef.h>
  6. #include <errno.h>
  7. #include <sys/types.h>
  8. #include <limits.h>
  9. #include <dirent.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12.  
  13. typedef char *pointer;        /* (void *) if you have it */
  14.  
  15. #define DULL (DIR *) NULL
  16. #define CULL (char *) NULL
  17.  
  18. int closedir(dirp)
  19. register DIR *dirp;        /* stream from opendir() */
  20. {
  21.   register int fd;
  22.  
  23.   if (dirp == DULL || dirp->dd_buf == CULL || dirp->dd_magic != _DIR_MAGIC) {
  24.     errno = EBADF;
  25.     return(-1);        /* invalid pointer */
  26.   }
  27.   fd = dirp->dd_fd;        /* bug fix thanks to R. Salz */
  28.   dirp->dd_magic = 0;        /* invalidate the entry */
  29.   free((pointer) dirp->dd_buf);
  30.   free((pointer) dirp);
  31.   return(close(fd));
  32. }
  33.